package com.vueblog.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vueblog.po.Anime;
import com.vueblog.service.AnimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AnimeShowController {
    private final int pageSize=21;


    @Autowired
    private AnimeService animeService;

    @GetMapping("/getShowAnime")
    public Object getIndexBlogs(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum){
        JSONObject jsonObject = new JSONObject();
        String orderBy = "watch_time desc";
        PageHelper.startPage(pageNum,pageSize,orderBy);
        List<Anime> animeList = animeService.findAllAnime();
        PageInfo<Anime> pageInfo = new PageInfo<Anime>(animeList);
        jsonObject.put("pageInfo",pageInfo);
        return jsonObject;
    }
}
